With \( \alpha = 0.1 \), the updates would increase \( \theta_0, \theta_1, \theta_2 \) and decrease \( \theta_3 \), nudging \( \hat{y} \) upward toward the target \( y = 2 \).
Building on Unit 16, this unit extends Gradient Descent to the multiple linear regression setting, formalizes the vectorized update rules, and covers two practical essentials: Feature Scaling and Feature Selection. We study two feature selection methods tailored to regression: the Correlation Filter (a model-independent filter) and p-value-based selection (an embedded method that inspects coefficient significance after training).
| Symbol | Meaning | Dimension |
|---|---|---|
| \( m \) | Number of rows / training examples | scalar |
| \( p-1 \) | Number of raw feature columns; after adding bias column, dimension is \( p \) | scalar |
| \( x_i \) | Feature vector for example \( i \) (with \( x_{i,0} = 1 \) for the bias) | \( p \times 1 \) |
| \( y_i \) | Target / label for example \( i \) | scalar |
| \( \theta \) | Model parameter / weight vector (\( \theta_0 \) is the bias) | \( p \times 1 \) |
| \( \hat{y}_i \) | Prediction: \( \hat{y}_i = \theta^T x_i \) | scalar |
| \( \alpha \) (or \( \eta \)) | Learning rate (step-size hyperparameter) | scalar |
Goal: Minimize the scalar function \( f(\theta) \).
Hyperparameters: Number of epochs \( N \), learning rate \( \eta \).
For the multi-variable linear hypothesis \( h_\theta(x) = \theta_0 + \theta_1 x_1 + \cdots + \theta_{p-1} x_{p-1} = \theta^T x \) (with \( x_0 = 1 \)) and MSE cost:
Defining the error per example \( e_i = \theta^T x_i - y_i \), we differentiate through the chain rule:
So the per-parameter gradient is:
In compact matrix notation, the whole gradient vector becomes:
And the simultaneous vectorized update:
Consider the first row of a 4-column dataset (bias column \( x_0 = 1 \), then 3 real features). Assume all four weights are initialized to \( \theta_0 = \theta_1 = \theta_2 = \theta_3 = 0.59 \), true label \( y = 2 \), and we are processing a batch of size 1 for simplicity.
| \( x_0 \) | \( x_1 \) | \( x_2 \) | \( x_3 \) | \( \hat{y} = \theta^T x \) | \( y \) | \( e = \hat{y} - y \) | \( \partial J/\partial \theta_0 \) | \( \partial J/\partial \theta_1 \) | \( \partial J/\partial \theta_2 \) | \( \partial J/\partial \theta_3 \) |
|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 1.5 | 2 | -1.2 | 1.65 | 2 | -0.35 | -0.35 · 1 | -0.35 · 1.5 | -0.35 · 2 | -0.35 · (-1.2) |
With \( \alpha = 0.1 \), the updates would increase \( \theta_0, \theta_1, \theta_2 \) and decrease \( \theta_3 \), nudging \( \hat{y} \) upward toward the target \( y = 2 \).
Gradient descent updates parameters by taking steps proportional to the slope of the cost function. The step size is controlled by the hyperparameter \( \alpha \) (learning rate).
When features have very different scales, gradient descent behaves inefficiently.
Without scaling:
Solution: Scale all features to comparable ranges (e.g., 0–1 min-max or standardized z-scores).
| Strategy | How it Works |
|---|---|
| Cost-Change Threshold | Stop when \( |J(t) - J(t-1)| < \varepsilon \), e.g., \( \varepsilon = 10^{-6} \) |
| Fixed Iterations | Run for a set number of epochs, say 1000 (simplest, but may waste compute or under-converge) |
| Validation Performance | Stop when validation error starts increasing → Early Stopping (prevents overfitting!) |
| Gradient Magnitude | Stop when \( \|\nabla J\| < \varepsilon \) — the gradient itself is nearly zero |
Feature selection improves model performance, training speed, and interpretability by discarding irrelevant or redundant features. We focus on two regression-tailored methods.
Earlier we saw Chi-Square, ANOVA, and other filter methods. For regression with a continuous target, the Pearson Correlation Coefficient is the most common filter. It measures the linear relationship between each feature and the target.
Like other filter methods, we can either keep the top-k columns or select columns exceeding a threshold (say \( |r| > 0.3 \)).
Note: Correlation works with one-hot encoded categorical variables, but ANOVA or Mutual Information are more statistically natural choices for purely categorical features.
After training a linear regression model, we can examine the statistical significance of each coefficient via its p-value. Formally, we test the null hypothesis:
Decision rule (typical):
| Family | How it Works | Examples |
|---|---|---|
| Filter | Select features before training, using statistical tests independent of the final model | Chi-square, ANOVA, Pearson Correlation, Mutual Information |
| Wrapper | Train the model many times with different subsets to pick the best-performing subset | Forward Selection, Backward Elimination, Recursive Feature Elimination (RFE) |
| Embedded | Feature selection happens during / as a byproduct of model training | Tree-based feature importances, Lasso (Unit 18!), p-value pruning |
Given \( X \in \mathbb{R}^{500 \times 20} \) (with bias column), \( \theta \in \mathbb{R}^{20 \times 1} \), \( y \in \mathbb{R}^{500 \times 1} \).
A. What are the dimensions of the prediction vector \( \hat{y} = X\theta \)?
B. What are the dimensions of the residual \( X\theta - y \) and of the full gradient \( \nabla J(\theta) \)?
A dataset of 8 features has Pearson correlations with the target shown below:
| Feature | Correlation (r) with Target |
|---|---|
| Age | +0.04 |
| Income | +0.72 |
| Zip-code (one-hot) | −0.02 |
| Education-Years | +0.31 |
| Height | −0.08 |
| Credit Score | −0.58 |
| Shoe Size | +0.01 |
| Family Size | +0.22 |
Task: Apply the threshold \( |r| > 0.3 \). Which features are kept?
Caution: Correlation only captures linear association. A strong non-linear relationship could have r ≈ 0 and would be dropped by this filter.
A student argues: "Since feature X's p-value is 0.08 (greater than 0.05), we have proven that X has no effect on the target whatsoever."
Mistake: Confusing "failure to reject \( H_0 \)" with "accepting \( H_0 \)." A high p-value is not proof of no effect.
Correct interpretation:
With p = 0.08, the observed data are not sufficiently unlikely under the null hypothesis \( \theta_j = 0 \). So we fail to reject \( H_0 \) at the α = 0.05 level. This does not mean the feature is definitely irrelevant — it might be a weak effect or the sample might be too small to detect it. Use domain knowledge and cross-validated performance before dropping it.
Mini-batch of 3 examples, 2 real features + bias column (p = 3):
Step 1: Predictions \( \hat{y} = X\theta \):
Step 2: Residual \( \hat{y} - y \):
Step 3: \( X^T (\hat{y} - y) \) (pre-factor):
Step 4: Divide by \( m = 3 \):
Two features predicting house price: size in sq ft (\( x_1 \in [500, 5000] \)) and bedrooms (\( x_2 \in [1, 5] \)). A GD step updates: \( \theta_1 := \theta_1 - \alpha \cdot 4000 \), \( \theta_2 := \theta_2 - \alpha \cdot 0.1 \).
Diagnosis: The gradient for \( \theta_1 \) is 40,000× larger than for \( \theta_2 \), so \( \theta_1 \) moves drastically while \( \theta_2 \) creeps. A single α cannot serve both well.
Fix — Standardize both features:
After standardization, \( \mu = 0 \) and \( \sigma = 1 \) for both features. Now both gradients are on the same scale and a single well-chosen α works for all parameters.
Feature A: Pearson r = +0.02 with target, p-value = 0.01 after regression.
Feature B: Pearson r = +0.55 with target, p-value = 0.20 after regression.
Step 1: Feature A (r = 0.02, p = 0.01)
Step 2: Feature B (r = 0.55, p = 0.20)
Takeaway: Correlation and p-values answer different questions. Use both, not either one in isolation.
From Problem 1 above, you found \( \nabla J(\theta) = [2/3,\ 2,\ 8/3]^T \). Starting \( \theta = [0, 1, 1]^T \), apply one gradient-descent step with \( \alpha = 0.1 \). Give the updated \( \theta \).
Match each description to the correct family: (F) Filter, (W) Wrapper, (E) Embedded.
A training run plots J(θ) vs. epoch. For each scenario, suggest which stopping strategy (or strategies) from Section 2.7 would be most appropriate and why.
Your score: 0 / 5